<?php

namespace app\admin\model\patrol;

use think\Model;

/**
 * 路线管理
 */
class Inspection extends Model
{

    

    

    // 表名
    protected $name = 'patrol_inspection';
    
    // 自动写入时间戳字段
    protected $autoWriteTimestamp = 'integer';

    // 定义时间戳字段名
    protected $createTime = 'createtime';
    protected $updateTime = 'updatetime';
    protected $deleteTime = false;

    // 追加属性
    protected $append = [

    ];
    

    protected static function init()
    {
        self::afterInsert(function ($row) {
            $pk = $row->getPk();
            $row->getQuery()->where($pk, $row[$pk])->update(['weigh' => $row[$pk]]);
        });
    }

    





    public  function childList($id){
        return $this->table('fa_patrol_child')->alias('m')
            ->join('patrol_inspection s','m.patrol_inspection_id=s.id')
            ->where('patrol_id',$id)
            ->field('count(m.patrol_inspection_id) as num,m.patrol_inspection_id,s.name as patrol_inspection_name')
            ->group('patrol_inspection_id')
            ->select();
    }


}
